package com.android.inputmethod.pinyin;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class DemoActivity extends AppCompatActivity {
    private LancooComposingView mComposingView;
    private LancooCandidateView mLancooCandidateView;
    private SkbContainer mSkbContainer;
    private LancooPinyinIME mLancooPinyinIME;
    private boolean mIsFirstOpen = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.demo);

        mComposingView = findViewById(R.id.composing_view);
        mLancooCandidateView = findViewById(R.id.v_candidates);
        mSkbContainer = findViewById(R.id.v_skb);

        mLancooPinyinIME = new LancooPinyinIME();
        mLancooPinyinIME.onCreate(this);
    }

    public void open(View v) {
        mSkbContainer.setVisibility(View.VISIBLE);

        if (mIsFirstOpen) {
            mIsFirstOpen = false;

            mLancooPinyinIME.onStartInput();
            mLancooPinyinIME.onCreateInputView(mComposingView, mLancooCandidateView, mSkbContainer);
        }

        mLancooPinyinIME.onStartInputView();
    }

    public void close(View v) {
        mLancooPinyinIME.onFinishInputView();
        mSkbContainer.setVisibility(View.GONE);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLancooPinyinIME.onDestroy(this);
    }
}